from functools import wraps
from flask import jsonify

def handle_request_error(f):
    @wraps(f)
    def decorated_function(*args, **kwargs):
        try:
            return f(*args, **kwargs)
        except Exception as e:
            # 将错误信息包装在 data 中，保持一致的返回格式
            return jsonify({
                "data": {
                    "error": str(e),
                    "available": False
                }
            }), 500
    return decorated_function